package classic150;

import java.util.Objects;

/**
 * <h3>leetcode</h3>
 *
 * @author BigFaceCat
 * @date 2024/1/20 20:04
 * @description <p>leetcode151_反转字符串中的单词_中等题</p>
 */
public class No151 {
    public static void main(String[] args) {
        String s = "a good   example";
        System.out.println(reverseWords(s));
    }

    public static String reverseWords(String s) {
        StringBuilder sb = new StringBuilder();
        String[] str = s.trim().split(" ");
        for (int i = str.length - 1; i >= 0; i--) {
            if (!Objects.equals(str[i], "")){
                sb.append(str[i]).append(" ");
            }
        }
        sb.delete(sb.length()-1, sb.length());
        return sb.toString();
    }
}
